﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

namespace DragonRescue3D
{
    /// <summary>
    /// Creates a temporary shake effect by quickly rotating the transform attached to the class instance
    /// </summary>
    public class ShakeCamera : MonoBehaviour
    {
        private bool Shaking = false;
        private float ShakeDecay;
        private float ShakeIntensity;
        private Vector3 OrigPos;
        private Quaternion OriglRot;

        /// <summary>
        /// Updates the rotation of the transform, tapering off ShkeIntesity on every call
        /// </summary>
        void Update()
        {
            if (ShakeIntensity > 0)
            {
                transform.position = OrigPos + Random.insideUnitSphere * ShakeIntensity;
                transform.rotation = new Quaternion(OriglRot.x + Random.Range(-ShakeIntensity, ShakeIntensity) * 0.2f,
                OriglRot.y + Random.Range(-ShakeIntensity, ShakeIntensity) * 0.2f,
                OriglRot.z + Random.Range(-ShakeIntensity, ShakeIntensity) * 0.2f,
                OriglRot.w + Random.Range(-ShakeIntensity, ShakeIntensity) * 0.2f);
                ShakeIntensity -= ShakeDecay;
            }
            else if (Shaking)
            {
                Shaking = false;
            }
        }

        /// <summary>
        /// Called once to initialise variables before the updates take affect
        /// </summary>
        public void Shake()
        {
            OrigPos = transform.position;
            OriglRot = transform.rotation;
            ShakeIntensity = 0.05f;
            ShakeDecay = 0.001f;
            Shaking = true;

#if ( UNITY_ANDROID || UNITY_IPHONE )
            Handheld.Vibrate();
#endif
        }
    }
}
#if NO_AND_ERROR
public void TEXT1() 
{
	int textNum = 1;
	if (textNum == 1) 
	{
		textNum = 2;
    }
}
public void TEXT2()
{
    int textNum = 1;
    if (textNum == 1)
    {
        textNum = 2;
    }
}
public void TEXT3()
{
    int textNum = 1;
    if (textNum == 1)
    {
        textNum = 2;
    }
}

public void TEXT4()
{
    int textNum = 1;
    if (textNum == 1)
    {
        textNum = 2;
    }
}

public void TEXT5()
{
    int textNum = 1;
    if (textNum == 1)
    {
        textNum = 2;
    }
}

public void TEXT6()
{
    int textNum = 1;
    if (textNum == 1)
    {
        textNum = 2;
    }
}

public void TEXT8()
{
    int textNum = 1;
    if (textNum == 1)
    {
        textNum = 2;
    }
}

public void TEXT9()
{
    int textNum = 1;
    if (textNum == 1)
    {
        textNum = 2;
    }
}

public void TEXT10()
{
    int textNum = 1;
    if (textNum == 1)
    {
        textNum = 2;
    }
}

public void TEXT11()
{
    int textNum = 1;
    if (textNum == 1)
    {
        textNum = 2;
    }
}

public void TEXT12()
{
    int textNum = 1;
    if (textNum == 1)
    {
        textNum = 2;
    }
}

public void TEXT13()
{
    int textNum = 1;
    if (textNum == 1)
    {
        textNum = 2;
    }
}

public void TEXT14()
{
    int textNum = 1;
    if (textNum == 1)
    {
        textNum = 2;
    }
}

public void TEXT15()
{
    int textNum = 1;
    if (textNum == 1)
    {
        textNum = 2;
    }
}

public void TEXT16()
{
    int textNum = 1;
    if (textNum == 1)
    {
        textNum = 2;
    }
}

public void TEXT17()
{
    int textNum = 1;
    if (textNum == 1)
    {
        textNum = 2;
    }
}
#endif